import axios from 'axios'
import { Toast } from 'antd-mobile';

const isDev=process.env.NODE_ENV==='development';

const ajax=axios.create({
    baseURL: isDev? 'http://rap2api.taobao.org/app/mock/163911':'真实的api地址'
});

ajax.interceptors.request.use((config)=>{
    Toast.loading('加载中…',0);
    return config;
});
ajax.interceptors.response.use(resp=>{
    Toast.hide();
    //当所有接口的返回格式相同时，可以在response函数中进行判断
    // if(resp.data.code===1&&resp.data.errorMsg==='OK'){
    // }else{
    //     Toast.fail(resp.data.errMsg)
    // }
    return resp;

});

export const getCarousel=()=>{
    return ajax.get('Carousel');
};
export const getSideBar=()=>{
    return ajax.get('SideBar');
};
export const getSideBarListById=(id)=>{
    return ajax.get(`SideBarlist/${id}`);
};
export const getProductDetail=(id)=>{
    return ajax.get(`Detail/${id}`);
};
export const login=(userInfo)=>{
    return ajax.post('login',{...userInfo});
};
export const checkAuthApi=(token)=>{
    return axios.post('http://rap2api.taobao.org/app/mock/163911/checkAuth',{token});
};